<!--
 * @Description: 消息配置列表
 * @Version: 1.0
 * @Author: Yuanjy
 * @Date: 2020-03-13 19:47:46
 * @LastEditors: Yuanjy
 * @LastEditTime: 2020-05-13 10:09:51
 -->
<template>
  <div class="app-container">
    <eHeader :query="query"/>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" border style="width: 100%;">
      <el-table-column prop="id" label="ID" />
      <el-table-column prop="type_text" label="消息类型" />
      <el-table-column prop="sub_type_text" label="消息子类型" />
      <el-table-column prop="send_handle" show-overflow-tooltip label="消息句柄" />
      <el-table-column prop="config" show-overflow-tooltip label="消息配置" />
      <!-- <el-table-column label="是否启用">
        <template slot-scope="scope">
          {{ scope.row.enabled ? '启用' : '未启用' }}
        </template>
      </el-table-column> -->
      <el-table-column prop="created_at" label="创建时间" />
      <el-table-column prop="updated_at" label="修改时间" />
      <el-table-column label="操作" width="320px" align="center">
        <template slot-scope="scope">
          <edit v-permission="['ADMIN']" :data="scope.row" :sup-this="supThis" />
          <el-popconfirm v-permission="['ADMIN']" title="确定删除本条数据吗？" @onConfirm="subDelete(scope.row.id)">
            <el-button slot="reference" type="danger" size="mini">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
  </div>
</template>

<script>
import initData from '@/mixins/initData'
import eHeader from './module/header'
import edit from './module/edit'

export default {
  components: { eHeader, edit },
  mixins: [initData],
  data() {
    return {
      delLoading: false,
      supThis: this
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    beforeInit() {
      this.url = '/admin/v1/message-config'
      const sort = 'id,desc'
      this.params = { page: this.page, limit: this.limit, sort: sort }
      const query = this.query
      const type = query.type
      const value = query.value
      if (type && value) { this.params[type] = value }
      return true
    },
    subDelete(id) {
      this.delLoading = true
      this.$api.enterprise.messageConfig
        .del(id)
        .then(res => {
          this.delLoading = false
          this.init()
          this.$notify({ title: '删除成功', type: 'success', duration: 2500 })
        }).catch(err => {
          this.delLoading = false
          console.log(err.response.data.message)
        })
    }
  }
}
</script>

<style scoped>

</style>
